#include "KeyPress.h"
#include <cstdio>
#include <QApplication>
#include <QKeyEvent>

KeyPress::KeyPress(QWidget *parent) : QWidget(parent)
{
}

void KeyPress::setProtocol(ClientProtocol *p)
{
        protocol = p;
}

void KeyPress::keyPressEvent(QKeyEvent *event)
{
        ServerData d;
        if (event->key() == Qt::Key_Up)
        {
                printf("UP\n");
                d.x = UP;
                protocol->sendToServer(d);
        }
        if (event->key() == Qt::Key_Down)
        {
                printf("Down\n");
                d.x = DOWN;
                protocol->sendToServer(d);
        }
        if (event->key() == Qt::Key_Left)
        {
                printf("Left\n");
                d.x = LEFT;
                protocol->sendToServer(d);
        }
        if (event->key() == Qt::Key_Right)
        {
                printf("Right\n");
                d.x = RIGHT;
                protocol->sendToServer(d);
        }
        if (event->key() == Qt::Key_Escape)
        {
                qApp->quit();
        }
}
